use crate::dao;
use crate::models::models::components::v2ray::subscription::ComponentV2raySubscription;
use crate::runtime::error::MagicBoxError;
use crate::runtime::response::{Code, MagicBoxResponse};
use crate::runtime::result::MagicBoxResult;

#[tauri::command(rename_all = "snake_case")]
pub(crate) async fn invoke_component_v2ray_save_subscription(subscription: ComponentV2raySubscription) -> MagicBoxResult<MagicBoxResponse<()>> {
    if "" == subscription.uuid || "" == subscription.name || "" == subscription.url {
        return Err(MagicBoxError::new(Code::ParameterError, "订阅配置无效，请检查配置参数是否完整"));
    }

    dao::components::v2ray::subscription::save_subscription_config(subscription.clone())?;

    Ok(MagicBoxResponse::new_empty_success())
}